package com.github.chxiaowu.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.chxiaowu.common.Result;
import com.github.chxiaowu.mongo.dto.PersonDto;
import com.github.chxiaowu.service.PersonService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(produces = { "application/json;charset=utf-8" })
@Api(description = "mongodb最佳实践", value = "PersonController")
public class PersonController {

	@Autowired
	PersonService personService;

	@SuppressWarnings("unchecked")
	@ApiOperation(value = "根据ID查询一个人", notes = "查询所有建筑物")
	@RequestMapping(value = "get.do", method = RequestMethod.GET)
	public Result<PersonDto> get(@RequestParam(required = false) String id) {
		PersonDto person = personService.getPerson(id);
		return Result.ok("sucess",person);
	}

	@SuppressWarnings("unchecked")
	@ApiOperation(value = "根据城市查询，该城市的所有人", notes = "根据城市查询，该城市的所有人(部分也)")
	@RequestMapping(value = "list.do", method = RequestMethod.GET)
	public Result<List<PersonDto>> list(@RequestParam(required = true) String city) {
		List<PersonDto> personList = personService.getPersonList(city);
		return Result.ok("sucess",personList);
	}
}